package br.com.android;

import android.app.Activity;
import android.os.Bundle;
import android.widget.*;
import android.view.*;
import android.app.*;

public class AppSalario extends Activity {
	private static final String[] percentual = { "De 40%", "De 45%", "De 50%" };
	ArrayAdapter<String> aPercentual;
	Spinner spnsal;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		Button btmostrar = (Button) findViewById(R.id.btcalcular);

		aPercentual = new ArrayAdapter<String>(this,
				android.R.layout.simple_spinner_item, percentual);

		spnsal = (Spinner) findViewById(R.id.spnopcoes);

		spnsal.setAdapter(aPercentual);

		btmostrar.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				double salario = 0, novo_sal = 0;

				EditText edsalario = (EditText) findViewById(R.id.edsalario);

				salario = Double.parseDouble(edsalario.getText().toString());

				switch (spnsal.getSelectedItemPosition()) {
				case 0:
					novo_sal = salario + (salario * 0.4);
					break;
				case 1:
					novo_sal = salario + (salario * 0.45);
					break;
				case 2:
					novo_sal = salario + (salario * 0.5);
					break;
				}
				AlertDialog.Builder dialog = new AlertDialog.Builder(
						AppSalario.this);
				dialog.setTitle("Novo Salário");
				dialog.setMessage("Seu novo salário é : R$"
						+ String.valueOf(novo_sal));
				dialog.setNeutralButton("OK", null);
				dialog.show();

			}
		});
	}
}